Set environment values (environments)
The environments view modifier allows injecting specific environment values into the current view hierarchy.
It serves a role similar to SwiftUI’s .environment(), but with a more explicit and controlled design tailored for Scripting.
Currently, the modifier supports:
editMode— controls editing behavior in views such asListopenURL— customizes how links are handled when tapped
These environment values affect all descendants within the modified view subtree.
Modifier Definition
1. editMode Environment
The editMode environment value controls the editing state of views that support editing behavior, such as List with row deletion or movement.
It must be provided as an Observable<EditMode> so views can reactively update when the editing state changes.
EditMode Type
Meaning of value
editMode Example
2. openURL Environment
The openURL environment value customizes how URLs are handled when interacted with inside the view tree.
It overrides the default behavior of components such as <Link>.
This is useful for:
- Deciding whether URLs should open inside the app or externally
- Filtering or validating URLs
- Redirecting URLs to different handlers
Function Signature
OpenURLActionResult
Result Behavior
iOS Requirement
prefersInApprequires iOS 26.0+- On earlier versions, the parameter may have no effect and system defaults will apply
openURL Example
Combined Example (editMode + openURL)
Notes & Behavior Summary
- The
environmentsmodifier applies only to the subtree where it is used. editModemust be anObservable<EditMode>for reactive updates.openURLreplaces default URL-handling behavior for all descendant views.- Returning
handled()stops further URL processing. systemAction()delegates handling back to the system.prefersInApprequires iOS 26.0+ and may be ignored on earlier versions.- Scripting’s environment system is explicit—only the values you define are injected.
